<?php
	require_once('init.php');
	
	//Isset Delete Action
	if (isset($_GET['f']) && $_GET['f'] == 'del') 
	{
		//Try Delete Column
		if (!$adminDB->executeSQL("delete from ".$util->contentdbName().".tbFile where id='".$_GET['id']."'", $connID)) 
		{
			echo "<script>alert('图片信息删除失败！');</script>";
		}
		else
		{
			//Insert AdminLog
			if(!$adminDB->executeSQL("insert into ".$util->userdbName().".tbAdminLog (fdOperatorID,fdAction,fdTarget,fdTime) values('".$_SESSION['adminid']."', 'DELETE', '".$util->contentdbName().".tbFile where id = ".$_GET['id']."' , now())", $connID))			
			{
				echo "<script>alert('图片信息删除成功！管理日志添加失败');</script>";
			}
			else
			{					
				echo "<script>alert('图片信息删除成功！');</script>";
			}
		}
	}
	
	if (isset($_GET['cid']) || isset($_POST['cid'])) 
	{	
		//Get Current Page
		if (! isset($_GET['page']) || $_GET['page'] == '') {$page = '1';} 
		else {$page = $_GET['page'];}
		
		//Set Shown Form Default New
		$isShow = 'N';
		//Get ContentID
		if (isset($_GET['cid'])) 
		{
			$cid = $_GET['cid'];
		}
		else 
		{
			$cid = $_POST['cid'];
		}
		$smarty->assign('cid',$cid);
		
		if(isset($_POST['stfile_http_path']))
		{
			foreach($_POST['stfile_http_path'] as &$value)
			{
				$adminDB->executeSQL("insert into ".$util->contentdbName().".tbFile (fdContentID,fdURL,fdSize,fdProxyID) values('".$cid."', '".$value."','0','0')", $connID);
				
				$adminDB->executeSQL("insert into ".$util->userdbName().".tbAdminLog (fdOperatorID,fdAction,fdTarget,fdTime) values('".$_SESSION['adminid']."', 'INSERT', '".$util->contentdbName().".tbFile(fdContentID,fdURL,fdSize,fdProxyID) values(".$cid.", ".$value.",'0','0')' , now())", $connID);			
				
			}	
			echo "<script>alert('图片信息添加成功！');</script>";			
		}
		
		//Query Product List	
		$sql = "select f.id,f.fdContentID,f.fdName,f.fdURL,f.fdSize,f.fdProxyID,f.fdUpdated from ".$util->contentdbName().".tbFile f where f.fdContentID = '".$cid."' order by f.id";
		$files = $pageDB->pageData($sql, $connID, 20, $page);		
		$smarty->assign('files', $files);
		$smarty->assign('isShow', $isShow);
		$smarty->display('admin_listfile.html');
	}
	
	$connDB->closeConnID();

?>